package cn.yunhe.server;

import cn.yunhe.dao.IResultDao;
import cn.yunhe.entity.Question;
import cn.yunhe.entity.Result;
import cn.yunhe.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ResultServer {
    SqlSession session = SqlSessionFactoryUtil.getSqlSession();
    IResultDao resultDao = session.getMapper(IResultDao.class);

    /**
     * 插入答案
     * @param result
     * @param qId
     * @return
     */
    public boolean InsertResult(String result,int qId,String answer){

        Map<String,Object> map = new HashMap<String, Object>();
        map.put("result",result);
        map.put("qId",qId);
        map.put("answer",answer);
        boolean flag = resultDao.InsertResult(map);
        if (flag){
            session.commit();
            return true;
        }else {
            return false;
        }
    }

    /**
     * 获取结果过
     * @param question
     * @return
     */
    public List<Result> SelectResult(Question question){
        return resultDao.SelectResult(question);
    }

}
